package model

import (
	"database/sql"
	"gorm.io/gorm"
)

type Route struct {
	BaseModel
	RouteName      string      `json:"route_name"`
	RouteNamespace string      `json:"route_namespace"`
	RouteHost      string      `json:"route_host"`
	RoutePath      []RoutePath `gorm:"ForeignKey:RouteID" json:"route_path"`
}

// 在同一个事务中更新数据
func (p *Route) AfterDelete(tx *gorm.DB) (err error) {
	if p.DeletedAt.Valid {
		tx.Exec("UPDATE route SET is_deleted = @is_deleted where id = @id",
			sql.Named("is_deleted", true), sql.Named("id", p.ID))
	}
	return
}
